<?php
/**
 * @title 剑指 Offer 11. 旋转数组的最小数字 - 迭代
 * @author start2004
 */

class Solution {

    /**
     * @param Integer[] $numbers
     * @return Integer
     */
    function minArray($numbers) {
        $min = null;

        /**
         * @since 2020-07-22 找到分界点
         */
        for($i=0, $len=count($numbers); $i<$len-1; $i++){
            if($numbers[$i+1] < $numbers[$i]){
                $min = $numbers[$i+1];
                break;
            } else {}
        }

        /**
         * @since 2020-07-22 完全升序
         */
        if($min === null){
            $min = $numbers[0];
        } else {}

        /**
         * @return
         */
        return $min;
    }
}




/**
 * @url http://127.0.0.1/leetcode/202007/2020.07.22.php
 */
$datas = [
    [3,3,1,3],
    [1,3,5],
    [3,4,5,1,2],
    [2,2,2,0,1],
];

include_once dirname(__DIR__) . DIRECTORY_SEPARATOR ."xhprof.php";
$xhprof = new Xhprof();
foreach ($datas as $data){
    var_dump($data);

    $obj = new Solution();
    $result = $obj->minArray($data);
    var_dump($result);
    echo str_repeat("<br>", 3);
}
$xhprof->end();
